import { createApp } from "vue";
import "virtual:windi.css";
import App from "./App.vue";
import router from "./router";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import { renderWithQiankun, qiankunWindow } from "vite-plugin-qiankun/dist/helper";

let app;

const bootstrap = (container) => {
  app = createApp(App);
  app.use(ElementPlus);
  app.use(router);
  app.mount(container ? container.querySelector("#app") : "#app");
};

const initQiankun = () => {
  renderWithQiankun({
    mount(props) {
      const { container, token } = props;
      console.log("主应用传递的token：" + token);
      bootstrap(container);
    },
    bootstrap() {},
    unmount(props) {
      app.unmount();
    },
  });
};

qiankunWindow.__POWERED_BY_QIANKUN__ ? initQiankun() : bootstrap();
